package com.loby.config;

import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;


/**
 * Created by lobyliang@qq.com
 * on 2019/11/29 8:40
 */
@Configuration
@EnableOAuth2Sso
@EnableResourceServer
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter
{
    @Override
    public void configure(WebSecurity web) throws Exception
    {
        //开放健康检查和API说明的端口
        web.ignoring().mvcMatchers("/test/**","/webjars/**","/actuator/**","/test/swagger-ui.html*");
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception
    {
        http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                .and()
                .requestMatchers().mvcMatchers("/**")
                .and()
                .authorizeRequests()
                .antMatchers( "/**").permitAll()
                .and().csrf().disable().cors();
        super.configure(http);
    }
}
